function TLCommentDlg(action,hSimHandle)

% SYNTAX:
%   TLCommentDlg('create',hSimHandle)
%   TLCommentDlg('close')
% 
% DESCRIPTION:
%    Function creates a modal dialog GUI with which a comment 
%    can be attached to a tlds simulation object.
%
% INPUT ARGUMENTS
%   hSimHandle     TLDS handle of simulation object
%
% OUTPUT ARGUMENTS:
%   -/-
%
% EXAMPLE
%   -/-
%
% SEE ALSO
%   -/-
%
% REMARK
%   -/-

% Copyright (c) 2003 dSPACE GmbH, GERMANY
% $Workfile: TLCommentDlg.m $ $Revision: 1.2 $ $Date: 2004/04/28 12:40:08MESZ $
% $Archive: /sw/TargetLink/Distribution/TargetLink_Base/Matlab/Tl/dlg/TLCommentDlg.m $


switch action
   
   case 'create'
      
      label              = tlds(hSimHandle,'get','label');
      comment            = tlds(hSimHandle,'get','comment');
      figdata.hSimHandle = tlds(hSimHandle,'get','handle');
      fontsize = get(0, 'FactoryUicontrolFontSize');
      fontname = get(0, 'FactoryUicontrolFontName');

      fig = figure( ...
         'Visible',                            'off', ...
         'DefaultUicontrolHorizontalAlign',    'left', ...
         'DefaultUicontrolFontname',           fontname, ...
         'DefaultUicontrolFontsize',           fontsize, ...
         'DefaultUicontrolUnits',              'pixels', ...
         'HandleVisibility',                   'off', ...
         'Colormap',                           [], ...
         'Name',                               ['Additional infos about simulation ''' label ''''] , ...
         'IntegerHandle',                      'off', ...
         'NumberTitle',                        'off', ...
         'MenuBar',                            'none', ...
         'WindowStyle',                        'modal');
      
      figPos = get(fig,'Position');
      
      % Construct common geometry constants.

      [commonGeom,textExtent] = ds_get_common_geometry;
      width       = commonGeom.sysButtonWidth;
      height      = commonGeom.sysButtonHeight;
      buttonDelta = commonGeom.sysButtonDelta;

      % dSPACE logo

      cx = commonGeom.figSideEdgeBuffer;
      cy = commonGeom.figBottomEdgeBuffer;
      [logoaxes,logo] = ds_create_logo(fig,cx,cy);
            
      % closebutton
      
      cx = figPos(3) - ...
         commonGeom.figSideEdgeBuffer - ...
         2*width - buttonDelta;
      uicontrol( ...
         'Parent',             fig, ...
         'String',             'Close', ...
         'Horizontalalign',    'center', ...
         'Position',           [cx cy width height], ...
         'Callback',           'TLCommentDlg(''close'');');

      % cancelbutton   
         
      cx = cx + width + buttonDelta;
      uicontrol( ...
         'Parent',             fig, ...
         'String',             'Cancel', ...
         'Horizontalalign',    'center', ...
         'Position',           [cx cy width height], ...
         'Callback',           'delete(gcbf)');

      % comment edit field
      
      cx = commonGeom.figSideEdgeBuffer;
      cy = cy + height + commonGeom.figBottomEdgeBuffer;
      width  = figPos(3) - 2*commonGeom.figSideEdgeBuffer;
      height = figPos(4) - height - ...
         2*commonGeom.figBottomEdgeBuffer - ...
         commonGeom.figTopEdgeBuffer;
             
      figdata.commentEdit = uicontrol( ...
         'Parent',             fig, ...
         'String',             comment, ...
         'Style',              'edit', ...
         'Min',                0, ...
         'Max',                2, ...
         'FontName',           'Courier New', ...
         'FontSize',           9, ...
         'BackGroundColor',    'w', ...
         'Position',           [cx cy width height]);
      
      set(fig,'UserData',figdata);
      set(fig,'Visible','on');
      
      
   case 'close'
      fig = gcbf;
      
      figdata = get(fig,'UserData');
      str = get(figdata.commentEdit,'String');
      comment = '';
   
      % create a row vector with characters and carriage returns
      for i=1:size(str,1)
         comment = [comment str(i,:) char(10)];
      end   
      comment = comment(1:end-1);
      
      tlds(figdata.hSimHandle,'set','comment',comment);
      close(fig);
      
   otherwise
      
      error(['Invalid action ' action]); 
end

